package com.sicheng.lc.周赛.分类.哈西表or计数or滑动窗口or双指针.抵消or期待某个元素;

import java.util.HashMap;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/6/16 14:45
 */
public class 必须拿起的最小连续卡牌数 {
    //    https://leetcode.cn/problems/minimum-consecutive-cards-to-pick-up/
    public int minimumCardPickup(int[] cards) {
        HashMap<Integer, Integer> map = new HashMap<>();
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < cards.length; i++) {
            if (map.containsKey(cards[i])) {
                min = Math.min(min, i - map.get(cards[i]) + 1);
            }
            map.put(cards[i], i);
        }
        if (min == Integer.MAX_VALUE)
            return -1;
        return min;
    }

    public static void main(String[] args) {

    }
}
